#!/bin/sh
cd `dirname $0`
pwd1=$(pwd| sed 's/\//\\\//g')
#echo ${pwd1}
echo s/\\\/opt\\\/Betasoft\\\/launch2/${pwd1}/g >script

which systemctl 1>/dev/null 2>/dev/null
# 0 is ok
if [ $? -ne 0 ]
then
    if [ "$1" = "uninstall" ]
    then
      chkconfig launch2 off
      chkconfig --del launch2
      service launch2 stop
      rm -f /etc/init.d/launch2
    else
      chmod +x ./launch2
      sed -f script  launch2 >/etc/init.d/launch2
#      cp launch2 /etc/init.d/
      chkconfig --add launch2
      chkconfig launch2 on
      service launch2 start
    fi
else
    if [ "$1" = "uninstall" ]
    then
      systemctl stop launch2.service
      systemctl disable launch2.service 1>/dev/nul  2>/dev/nul
      rm -f /usr/lib/systemd/system/launch2.service
    else
     # cp launch2.service /usr/lib/systemd/system
      sed -f script launch2.service >/usr/lib/systemd/system/launch2.service
      systemctl enable launch2.service 1>/dev/nul  2>/dev/nul
      systemctl start launch2.service 
    fi
fi